#include <mutex>
class singleInstance
{
private:
	static singleInstance* single_instance;
public:
	static singleInstance* getInstance()
	{
		static std::mutex m;
		if (single_instance == nullptr) {
			std::unique_lock<mutex> u(m);
			//m.lock();
			if (single_instance == nullptr) {
				single_instance = new singleInstance();
			}
			//m.unlock();
		}
		return single_instance;
	}
	static void releaseInstance() //释放单例的静态方法，也可以使用智能指针
	{
		if (single_instace) {
			delete single_instance;
			single_instance = nullptr;
		}
	}
	//将构造函数、拷贝构造函数、拷贝赋值运算符，都设为私有
private:
	singleInstance()
	{}
	singleInstance(const singleInstance& single_instance) = delete;
	singleInstance& singleInstance(const singleInstance& single_instance) = delete;
};
//初始化静态变量
singleInstance* singleInstance::single_instance = nullptr;
std::mutex singleInstance::m;

class Singleton
{
    public:
    	//3、提供一个全局访问点获取单例对象
        	static Singleton* GetInstance()
            	{
                    		return _inst;
                }
                private:
                	//1、将构造函数设置为私有，并防拷贝
                    	Singleton()
                        	{}
                            	Singleton(const Singleton&) = delete;
                                	Singleton& operator=(const Singleton&) = delete;
                                    	//2、提供一个指向单例对象的static指针
                                        	static Singleton* _inst;
};

//在程序入口之前完成单例对象的初始化
Singleton* Singleton::_inst = new Singleton;                }
}